package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.NbChapterKnowledgePoints;
import com.ruoyi.teach.service.INbChapterKnowledgePointsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 章节知识点关联Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/chapter_knowledge_points")
public class NbChapterKnowledgePointsController extends BaseController
{
    @Autowired
    private INbChapterKnowledgePointsService nbChapterKnowledgePointsService;

    /**
     * 查询章节知识点关联列表
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_knowledge_points:list')")
    @GetMapping("/list")
    public TableDataInfo list(NbChapterKnowledgePoints nbChapterKnowledgePoints)
    {
        startPage();
        List<NbChapterKnowledgePoints> list = nbChapterKnowledgePointsService.selectNbChapterKnowledgePointsList(nbChapterKnowledgePoints);
        return getDataTable(list);
    }

    /**
     * 导出章节知识点关联列表
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_knowledge_points:export')")
    @Log(title = "章节知识点关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NbChapterKnowledgePoints nbChapterKnowledgePoints)
    {
        List<NbChapterKnowledgePoints> list = nbChapterKnowledgePointsService.selectNbChapterKnowledgePointsList(nbChapterKnowledgePoints);
        ExcelUtil<NbChapterKnowledgePoints> util = new ExcelUtil<NbChapterKnowledgePoints>(NbChapterKnowledgePoints.class);
        util.exportExcel(response, list, "章节知识点关联数据");
    }

    /**
     * 获取章节知识点关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_knowledge_points:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(nbChapterKnowledgePointsService.selectNbChapterKnowledgePointsById(id));
    }

    /**
     * 新增章节知识点关联
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_knowledge_points:add')")
    @Log(title = "章节知识点关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NbChapterKnowledgePoints nbChapterKnowledgePoints)
    {
        return toAjax(nbChapterKnowledgePointsService.insertNbChapterKnowledgePoints(nbChapterKnowledgePoints));
    }

    /**
     * 修改章节知识点关联
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_knowledge_points:edit')")
    @Log(title = "章节知识点关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NbChapterKnowledgePoints nbChapterKnowledgePoints)
    {
        return toAjax(nbChapterKnowledgePointsService.updateNbChapterKnowledgePoints(nbChapterKnowledgePoints));
    }

    /**
     * 删除章节知识点关联
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_knowledge_points:remove')")
    @Log(title = "章节知识点关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nbChapterKnowledgePointsService.deleteNbChapterKnowledgePointsByIds(ids));
    }
}
